'Name:			oeRandom.vb														##
'Author:		schachmat														##
'Last modified:	21.8.2007														##
'Status:																		##
'	functionality:			20%													##
'	documentation intern:	0%													##
'	documentation extern:	0%													##
'Comments:																		##
'TODO: ComparExtend																##
'																				##
'																				##
'																				##
'																				##
'#################################################################################


'The MIT License

'Copyright (c) 2007 Markus Teich

'Permission is hereby granted, free of charge, to any person obtaining a copy
'of this software and associated documentation files (the "Software"), to deal
'in the Software without restriction, including without limitation the rights
'to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
'copies of the Software, and to permit persons to whom the Software is
'furnished to do so, subject to the following conditions:

'The above copyright notice and this permission notice shall be included in
'all copies or substantial portions of the Software.

'THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
'IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
'FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
'AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
'LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
'OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
'THE SOFTWARE.

Imports OE
Imports OE.Core

Public Class oeRandom

    Private Shared Rnd As New Random(My.Computer.Clock.TickCount)

    Public Shared Sub Init()
        oeLog.LogInfo("oeRandom wird initialisiert...")
        Rnd = New Random(My.Computer.Clock.TickCount)
        oeLog.LogOk("oeRandom erfolgreich initialisiert")
    End Sub

    Public Shared Function Vector3(ByVal LenMax As Single, Optional ByVal LenMin As Single = 0) As oeVector3
        If LenMax <> 0 Or LenMin <> 0 Then
            Dim temp As oeVector3 = Vector3Norm() * LenMax
            Return New Core.oeVector3(oeVector3.InterpolateCoords(temp, temp * LenMin, RndSingle()))
        Else
            Return New Core.oeVector3()
        End If
    End Function

    Public Shared Function Vector3Norm() As oeVector3
        Return +(New oeVector3(RndSingle() * 2 - 1, _
                               RndSingle() * 2 - 1, _
                               RndSingle() * 2 - 1))
    End Function

    Public Shared Function Color(Optional ByVal Alpha As Single = 1.0) As oeColor
        Return New oeColor(Convert.ToSingle(IIf(Alpha < 0.0 Or Alpha > 1.0, RndSingle(), Alpha)), _
                           RndSingle(), _
                           RndSingle(), _
                           RndSingle())
    End Function

    Public Shared Function RndSingle() As Single
        Return Convert.ToSingle(Rnd.NextDouble)
    End Function
End Class
